package org.uim.cricket.entities.persist.impl;

import org.uim.cricket.entities.fielding.SingleFielding;
import org.uim.cricket.entities.persist.CricketEntityPersistable;

public class XMLSingleFieldingPersist implements CricketEntityPersistable<SingleFielding> {

	private String tagName = "Fielding";
	
	@Override
	public String doPersist(SingleFielding object) {
		if (object == null) return "";
		StringBuilder sb = new StringBuilder();

		if (tagName.length() > 0) sb.append("<").append(tagName);

		sb.append(" type=\"").append(object.getFieldType()).append("\"");
		sb.append(" batsman=\"").append(object.getBatsman().getId()).append("\"");
		sb.append(" inning=\"").append(object.getInning()).append("\"");
		
		if (tagName.length() > 0) sb.append(" />");
		return sb.toString();
	}

}
